package com.bonc.ioc.service.impl;

import com.bonc.ioc.base.service.BaseService;
import com.bonc.ioc.dao.StandardBasicDataMapper;
import com.bonc.ioc.service.StandardBasicDataService;
import com.bonc.ioc.vo.StandardBasicDataVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @version 1.0
 * @description:
 * @author: wangqinglin
 * @date: 2021/3/26 14:20
 * @change : 2021/3/26 14:20 by q8541q@163.com  for init
 */
@Service
public class StandardBasicDataServiceImpl extends BaseService implements StandardBasicDataService {

    @Resource
    private StandardBasicDataMapper standardBasicDataMapper;

    @Override
    public int deleteByPrimaryKey(String id) {
        return standardBasicDataMapper.delete(id);
    }

    @Override
    public int save(StandardBasicDataVo record) {

        if (record.getId() != null) {
            fillModifyTimeInfo(record);
            return standardBasicDataMapper.update(record);
        } else {
            fillBasicTimeInfo(record);
            fillModifyTimeInfo(record);
            return standardBasicDataMapper.save(record);
        }
    }

    @Override
    public StandardBasicDataVo selectByPrimaryKey(Long id) {
        return standardBasicDataMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKey(StandardBasicDataVo record) {
        return standardBasicDataMapper.update(record);
    }

    @Override
    public List<StandardBasicDataVo> getBasicFieldInfoList(String id) {
        return standardBasicDataMapper.getBasicFieldInfoList(id);
    }

    private void fillModifyTimeInfo(StandardBasicDataVo record) {
        record.setModifyTime(new Date());
    }

    private void fillBasicTimeInfo(StandardBasicDataVo record) {
        record.setCreateTime(new Date());
    }

}

